﻿using Abp.Domain.Entities;
using IntelligentAgriculture.Contracts.Interface.ColumnManagements;
using IntelligentAgriculture.Contracts.Interface.EarTagService;
using IntelligentAgriculture.Contracts.Interface.IManagements;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Services.Management;
using IntelligentAgriculture.WebAPI.Application.Command.ColumnManageCommand;
using IntelligentAgriculture.WebAPI.Application.Command.ManageCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.ColumnManageCommandHandler
{
    public class ColumnManageAddCommandHandler : IRequestHandler<ColumnManageAddCommand, Results<int>>
    {
        private readonly  IColumnManageService _icolumnManageService;

        public ColumnManageAddCommandHandler(IColumnManageService icolumnManageService)
        {
            _icolumnManageService= icolumnManageService;
        }

        /// <summary>
        /// 处理添加栏位管理命令的方法
        /// </summary>
        /// <param name="request">栏位管理添加命令的请求对象</param>
        /// <param name="cancellationToken">取消令牌，用于取消操作</param>
        /// <returns>表示异步操作结果的结果对象，包含一个整数类型的结果</returns>
        public async Task<Results<int>> Handle(ColumnManageAddCommand request, CancellationToken cancellationToken)
        {

            try
            {
                var list = new Columnmanagement()
                {
                    StartingNumbering = request.StartingNumbering,
                    ColumnCount = request.ColumnCount,
                    ColumnManagementId = request.ColumnManagementId,
                    ColumnName = request.ColumnName,
                    Prefix = request.Prefix,
                    ResponsiblePerson = request.ResponsiblePerson,
                    RidgepoleId = request.RidgepoleId,
                    RidgepoleTypeId = request.RidgepoleTypeId,
                };
                var result = await _icolumnManageService.Add(list);
                return Results<int>.DataResult(result);
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}
